from selenium import webdriver


class Browser(object):
    """单例模式-----无论实例化多少次，始终只有一个浏览器"""
    dr = None  # 浏览器对象
    __instance = None  # 实例地址

    # chrome_driver=r"E:\woniu\woniusales_ui_test_3\browser\driver\chromedriver.exe"
    firefox_driver=r"E:\woniu\woniusales_ui_test_3\browser\driver\geckodriver.exe"
    ie_driver=r"E:\woniu\woniusales_ui_test_3\browser\driver\IEDriverServer.exe"

    def __new__(cls, browser_name="chrome", *args, **kwargs):
        if cls.dr is None:
            if browser_name.lower() in ("chrome", "谷歌"):
                cls.dr = webdriver.Chrome()
            elif browser_name.lower() in ("firefox", "火狐"):
                cls.dr = webdriver.Firefox(executable_path=cls.firefox_driver)
            elif browser_name.lower() in ("ie",):
                cls.dr = webdriver.Ie(executable_path=cls.ie_driver)
            else:
                raise NameError("你选择的浏览器不受支持！")
            cls.__instance=object.__new__(cls)   #必须返回new对象

        return  cls.__instance

    # def __init__(self):
    #     print(self.dr)



if __name__ == '__main__':
    Browser()
